﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using RBS.Common;
using RBS.Core.Model;
namespace RBS.Core.BLL .Hotel{
	 	//酒店座位信息表
		public partial class H_Hotel_Seat
	{
   		     
		private readonly RBS.Core.DAL.Hotel.H_Hotel_Seat dal=new RBS.Core.DAL.Hotel.H_Hotel_Seat();
		public H_Hotel_Seat()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(RBS.Core.Model.Hotel.H_Hotel_Seat model)
		{
						return dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(RBS.Core.Model.Hotel.H_Hotel_Seat model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RBS.Core.Model.Hotel.H_Hotel_Seat GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public RBS.Core.Model.Hotel.H_Hotel_Seat GetModelByCache(int Id)
		{
			
			string CacheKey = "H_Hotel_SeatModel-" + Id;
			object objModel = RBS.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = RBS.Common.ConfigHelper.GetConfigInt("ModelCache");
						RBS.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (RBS.Core.Model.Hotel.H_Hotel_Seat)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<RBS.Core.Model.Hotel.H_Hotel_Seat> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<RBS.Core.Model.Hotel.H_Hotel_Seat> DataTableToList(DataTable dt)
		{
            var modelList = new List<RBS.Core.Model.Hotel.H_Hotel_Seat>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                for (int n = 0; n < rowsCount; n++)
                {
                    var model = new RBS.Core.Model.Hotel.H_Hotel_Seat();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["AOBT"].ToString() != "")
                    {
                        model.AOBT = int.Parse(dt.Rows[n]["AOBT"].ToString());
                    }
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = int.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    if (dt.Rows[n]["HotelId"].ToString() != "")
                    {
                        model.HotelId = int.Parse(dt.Rows[n]["HotelId"].ToString());
                    }
                    model.Floor = dt.Rows[n]["Floor"].ToString();
                    model.Category = dt.Rows[n]["Category"].ToString();
                    model.Hall = dt.Rows[n]["Hall"].ToString();
                    model.RoomNumber = dt.Rows[n]["RoomNumber"].ToString();
                    model.Name = dt.Rows[n]["Name"].ToString();
                    if (dt.Rows[n]["Numbers"].ToString() != "")
                    {
                        model.Numbers = int.Parse(dt.Rows[n]["Numbers"].ToString());
                    }
                    model.Picture = dt.Rows[n]["Picture"].ToString();  
                    modelList.Add(model);
                }
            }
            return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
#endregion


	    #region  ExtensionMethod
	    public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
	    {
            return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
	    }

	    #endregion  ExtensionMethod

        public bool UpdateStatus(int hotelId, string dineTable, int status)
		    {
                return dal.UpdateStatus(hotelId, dineTable, status);
		    }


        /// <summary>
        /// 获取能订餐的座位
        /// </summary>
        /// <param name="hid"></param>
        /// <param name="time1"></param>
        /// <param name="time2"></param>
        /// <returns></returns>
        public List<RBS.Core.Model.Hotel.H_Hotel_Seat> GetSeatList(int hid, DateTime time1, DateTime time2)
        {
            DataTable dt = dal.GetSeatList(hid, time1, time2).Tables[0];
            return DataTableToList(dt);

        }
	}
}